#!/usr/bin/env python
# -*- coding: utf-8 -*-

import wx
import context
import util
import bank
class Builder:
    
    def __init__(self, conf):
        self.conf = conf
        self.list = wx.ListCtrl(self.conf.target_panel,-1, style = wx.LC_REPORT, size=(500, 200))
        pass
    
    def setData(self):
        self.list.InsertColumn(0, u"名前")
        self.list.InsertColumn(1, u"置換文字列")
        self.list.InsertColumn(2, u"タイプ")
        self.list.InsertColumn(3, u"最大数")
        for i, v in enumerate(context.Config["target"]):
            self.list.InsertStringItem(i, util.encode(v["name"]))
            self.list.SetStringItem(i, 1, v["str"])
            self.list.SetStringItem(i, 2, v["type"])
            try:
                self.list.SetStringItem(i, 3, v["max"].__str__())
            except Exception:
                pass
            
          
    
    def build(self):
        self.setData()
            
        self.list.Bind(wx.EVT_LIST_ITEM_FOCUSED, self.test)
        
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.list)
        
        
        
        self.conf.target_panel.SetSizer(sizer)
    
    def clearAll(self):
        self.list.ClearAll()
        
        
    def test(self, evt):
        print "test"
        print self.list.GetFocusedItem()
        print evt
        item = evt.GetItem()
        print item.GetText()
        print item.GetId()
        print self.list.GetItem(item.GetId(), 1).GetText()

        
        